package edu.hawaii.myisern.action;

import java.util.List;
import edu.hawaii.myisern.model.MyIsernSanityCheck;
import edu.hawaii.myisern.model.MyIsernModel;
import edu.hawaii.myisern.model.SanityError;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;

/**
 * Provides a web interface for sanity report.
 * 
 * @author Ed Kim
 * @author Jon Lao
 * @author JianFei Liao
 * @author Jared Sunouchi
 */
public class ReportActionBean implements ActionBean {

  /** Required by the ActionBean interface. */
  private ActionBeanContext context;
  /** An singleton instance of the MyIsernModel. */
  private MyIsernModel myModel = MyIsernModel.getInstance();
  
  private List<SanityError> invalidYearsInCollaboration;
  private List<SanityError> invalidAffiliatedResearchersInOrganization;
  private List<SanityError> invalidOrganizationInResearcher;
  private List<SanityError> invalidOrganizationsInCollaboration;
  
  private List<SanityError> emptyOrganizationInResearcher;
  private List<SanityError> emptyAffiliatedResearchersInOrganization;
  private List<SanityError> emptyOrganizationsInCollaboration;
  
  
  /**
   * Returns the context. Required by the interface.
   * 
   * @return the ActionBeanContext.
   */
  public ActionBeanContext getContext() {
    return context;
  }

  /**
   * Sets the context. Required by the interface.
   * 
   * @param context The ActionBeanContext to set.
   */
  public void setContext(ActionBeanContext context) {
    this.context = context;
  }
  
  /**
   * Gets the list of invalid organizations for all the researchers.
   * 
   * @return A list of invalid organizations.
   */
  public List<SanityError> getInvalidOrganizationsInResearcher() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.invalidOrganizationInResearcher = checker.invalidOrganizationInResearcher();
    return this.invalidOrganizationInResearcher;
  }
  
  /**
   * Gets the list of invalid researchers for all the organizations.
   * 
   * @return A list of invalid researchers.
   */
  public List<SanityError> getInvalidAffiliatedResearchersInOrganization() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.invalidAffiliatedResearchersInOrganization = checker.
        invalidAffiliatedResearchersInOrganization();
    return this.invalidAffiliatedResearchersInOrganization;
  }
  
  /**
   * Gets the list of invalid collaborating organizations for all the collaborations.
   * 
   * @return A list of invalid collaborating organizations.
   */
  public List<SanityError> getInvalidOrganizationsInCollaboration() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.invalidOrganizationsInCollaboration = checker.invalidOrganizationsInCollaboration();
    return this.invalidOrganizationsInCollaboration;
  }
  
  /**
   * Gets the list of invalid years for all the collaborations.
   * 
   * @return A list of invalid years.
   */
  public List<SanityError> getInvalidYearsInCollaboration() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.invalidYearsInCollaboration = checker.invalidYearsInCollaboration();
    return this.invalidYearsInCollaboration;
  }
  
  /**
   * Gets the empty or null organization entries from researcher.
   * 
   * @return list of empty organizations in researcher
   */
  public List<SanityError> getEmptyOrganizationInResearcher() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.emptyOrganizationInResearcher = checker.emptyOrganizationInResearcher();
    return this.emptyOrganizationInResearcher;
  }
  
  /**
   * Gets the empty or null organization entries from collaboration.
   * 
   * @return list of empty organizations in collaboration
   */
  public List<SanityError> getEmptyAffiliatedResearchersInOrganization() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.emptyAffiliatedResearchersInOrganization = checker.
        emptyAffiliatedResearchersInOrganization();
    return this.emptyAffiliatedResearchersInOrganization;
  }
  
  /**
   * Gets the empty or null organization entries from collaboration.
   * 
   * @return list of empty organizations in researcher
   */
  public List<SanityError> getEmptyOrganizationsInCollaboration() {
    MyIsernSanityCheck checker = new MyIsernSanityCheck(this.myModel);
    this.emptyOrganizationsInCollaboration = checker.emptyOrganizationsInCollaboration();
    return this.emptyOrganizationsInCollaboration;
  }
    
  /**
   * Shows a sanity report.
   * 
   * @return A Resolution indicating to redisplay report.jsp pagse.
   * @throws Exception error message
   */
  @DefaultHandler
  public Resolution showReport() throws Exception {
    return new RedirectResolution("/report.jsp").flash(this);
  }
}
